import requests
import random
from requests_toolbelt import MultipartEncoder
from fake_useragent import UserAgent
import json
from urllib import request
from urllib import parse

request_url = 'http://125.35.6.80:8181/ftban/itownet/fwAction.do?method=getBaInfo'
request_url2 = 'http://125.35.6.80:8181/ftban/itownet/fwAction.do?method=getAttachmentCpbz'

user_agents = [
    'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36',
    'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36',
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Edge/16.16299',
    'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'
]

headers2 = {
    'Accept': 'application/json, text/javascript, */*; q=0.01',
    'Accept-Encoding': 'gzip, deflate, br',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Connection': 'keep-alive',
    'Content-Length': '46',
    'Content-Type': 'application/x-www-form-urlencoded',
    'Host': '125.35.6.80:8181',
    'Origin': 'http://125.35.6.80:8181',
    'Referer': 'http://125.35.6.80:8181/ftban/itownet/hzp_ba/fw/pz.jsp?processid=20170731140739a1dcc&nid=20170731140739a1dcc',
    'User-Agent': user_agents[random.randrange(0,4)],
    'X-Anit-Forge-Code': '0',
    'X-Anit-Forge-Token': 'None',
    'X-Requested-With': 'XMLHttpRequest',
}

processid = '20170731140739a1dcc'
form_data = {"processId": processid, "j_captcha": 'null'}
form_data = {"procrssId": processid}


# print(headers2)
#
# r = requests.post(request_url, data=form_data)
# print(r.text)
# params="?"
# for key in form_data:
#     params = params + key + "=" + form_data[key] + "&"
# print("Get方法参数："+params)
data = parse.urlencode(form_data).encode('utf-8')
data = form_data
req = request.Request(request_url, headers=headers2, data=data)  # POST方法
# req = request.Request(url+params)  # GET方法
page = request.urlopen(req).read()
page = page.decode('utf-8')

print(page)
